package com.mall.seckill.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.mall.seckill.model.SeckillActivity;
import com.mall.common.util.RespResult;
import lombok.RequiredArgsConstructor;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.mall.seckill.service.ISeckillActivityService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.util.List;


/**
 * <p>
 *  控制器
 * </p>
 *
 * @author Darren
 * @since 2022-09-28
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@Api(tags = "REST - 秒杀活动表")
@RestController
@RequestMapping("/activity")
public class SeckillActivityController {
    private final ISeckillActivityService service;

    @PostMapping("/addSeckillActivity")
    @ApiOperation(value = "新增")
    public RespResult addSeckillActivity(@RequestBody SeckillActivity seckillactivity){
        boolean flag = service.addSeckillActivity(seckillactivity);
        return RespResult.ok(flag ? "创建成功" : "创建失败");
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "根据id删除")
    public RespResult deleteById(@PathVariable("id") String id){
        boolean flag = service.deleteById(id);
        return RespResult.ok(flag ? "删除成功" : "删除失败");
    }

    @PutMapping("/updateSeckillActivity")
    @ApiOperation(value = "更新")
    public RespResult updateSeckillActivity(@RequestBody SeckillActivity seckillactivity){
        boolean flag = service.updateSeckillActivity(seckillactivity);
        return RespResult.ok(flag ? "更新成功" : "更新失败");
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询")
    public RespResult getById(@PathVariable("id") String id){
        return RespResult.ok(service.getById(id));
    }

    @PostMapping("/selectList")
    @ApiOperation(value = "根据条件查询全部数据")
    public RespResult selectList(SeckillActivity seckillactivity){
        return RespResult.ok(service.selectList(seckillactivity));
    }

    @PostMapping("/selectPage")
    @ApiOperation(value = "分页查询")
    public RespResult selectPage(Page<SeckillActivity> page, SeckillActivity seckillactivity){
        return RespResult.ok(service.selectPage(page, seckillactivity));
    }

    @GetMapping
    @ApiOperation(value = "有效活动列表")
    public RespResult<List<SeckillActivity>> validActivity() {
        return RespResult.ok(service.validActivity());
    }

}